<template>
<div style="height:700px;background-color:#fff;display:flex; justify-content:space-between;">
  <div>
    <a-tree 
    show-line 
    :default-expanded-keys="['0-0-0']" 
    style="display:inline-block;"
     v-model="checkedKeys"
    :expanded-keys="expandedKeys"
    :auto-expand-parent="autoExpandParent"
    :selected-keys="selectedKeys"
    :tree-data="treeData"
    @expand="onExpand"
    @select="onSelect"
    >
    <a-icon slot="switcherIcon" type="down" />
  </a-tree>
  </div>
  <a-card :bordered="false" style="width:100%;">
    
  <div class="content" style="display:inline-block;margin-left:50px;">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="工作内容">
              <a-input placeholder="请输入工作内容" v-model="queryParam.workDetail"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="工作票签发人签名">
              <a-input placeholder="请输入工作票签发人签名" v-model="queryParam.ticketAssignSign"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
              <a-form-item label="风电场名称">
                <j-select-depart placeholder="请选择风电场名称" v-model="queryParam.orgName"/>
              </a-form-item>
            </a-col>
         
          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              
             
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <!-- <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('电气第一种工作票')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div> -->

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="Detail(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="Detail1(record)" >详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
     
    </div>

    <one-electrical-modal ref="modalForm" @ok="modalFormOk"></one-electrical-modal>
    </div>

     <a-modal
      title="单据"
      :width="width"
      :visible="visible"
      :confirm-loading="confirmLoading"
      @ok="handleOk"
      @cancel="handleCancel"
    >
    <template slot="footer">
            <a-select
          label-in-value
          :default-value="{ key: 'main' }"
          style="width: 120px"
          @change="handleChange"
        >
          <a-select-option value="main">
            电气倒闸
          </a-select-option>
          <a-select-option value="danger">
            危险点措施票
          </a-select-option>
          <a-select-option value="before">
            操作前表
          </a-select-option>
          <a-select-option value="after">
            操作后表
          </a-select-option>
        </a-select>
        <a-button key="back" @click="handleCancel">
          返回
        </a-button>
         <a-button v-print="'#printContent'" ghost type="primary" >打印</a-button>
         <a-button  type="primary" @click="yes" >确定</a-button>
      </template>
      <Elemain :bb="value" id="printContent" v-if="elemain" ref="ch"/>
      <Eledanger :bb="value" id="printContent" v-if="eledanger" ref="ch"/>
      <Elebefore :bb="value" id="printContent" v-if="elebefore" ref="ch"/>
      <Eleafter :bb="value" id="printContent" v-if="eleafter" ref="ch"/>
    </a-modal>


     <a-modal
      title="单据"
      :width="width"
      :visible="visible1"
      :confirm-loading="confirmLoading1"
      @ok="handleOk1"
      @cancel="handleCancel1"
    >
    <template slot="footer">
            <a-select
          label-in-value
          :default-value="{ key: 'main' }"
          style="width: 120px"
          @change="handleChange1"
        >
          <a-select-option value="main">
            电气倒闸
          </a-select-option>
          <a-select-option value="danger">
            危险点措施票
          </a-select-option>
          <a-select-option value="before">
            操作前表
          </a-select-option>
          <a-select-option value="after">
            操作后表
          </a-select-option>
        </a-select>
        <a-button key="back" @click="handleCancel1">
          返回
        </a-button>
         <a-button v-print="'#printContent'" ghost type="primary" >打印</a-button>
      </template>
      <Elemain1 :bb="value" id="printContent" v-if="elemain1" ref="ch"/>
      <Eledanger1 :bb="value" id="printContent" v-if="eledanger1" ref="ch"/>
      <Elebefore1 :bb="value" id="printContent" v-if="elebefore1" ref="ch"/>
      <Eleafter1 :bb="value" id="printContent" v-if="eleafter1" ref="ch"/>
    </a-modal>


  </a-card>
   </div>
</template>

<script>
const treeData = [
  {
    title: '工作票办理流程',
    key: '0-0',
    children: [
      {
        title: '草稿箱',
        key: 'operation_ticket-list-procedure-draft-OneElectricalList',
      },
      {
        title: '监护人审核',
        key: 'operation_ticket-list-procedure-guardian-OneElectricalList',
      },
      {
        title: '值班负责人审核',
        key: 'operation_ticket-list-procedure-onduty-OneElectricalList',
      },
      {
        title: '打印票',
        key: 'operation_ticket-list-procedure-print-OneElectricalList',

      },
      {
        title: '存档票',
        key: 'operation_ticket-list-procedure-file-OneElectricalList',
      },
      {
        title: '作废票',
        key: 'operation_ticket-list-procedure-cancel-OneElectricalList',
      },
      {
        title: '未执行票',
        key: 'operation_ticket-list-procedure-unexecuted-OneElectricalList',
      },
    ],
  },
 
];

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import OneElectricalModal from './modules/OneElectricalModal'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import JSelectDepart from '@/components/jeecgbiz/JSelectDepart'
  import JSearchSelectTag from '@/components/dict/JSearchSelectTag'
  import { httpAction, getAction,postAction,putAction } from '@/api/manage'
  import Elemain from '@/components/form/Elemain'
  import Eledanger from '@/components/form/Eledanger'
  import Elebefore from '@/components/form/Elebefore'
  import Eleafter from '@/components/form/Eleafter'
  import Elemain1 from '@/components/form/Elemain1'
  import Eledanger1 from '@/components/form/Eledanger1'
  import Elebefore1 from '@/components/form/Elebefore1'
  import Eleafter1 from '@/components/form/Eleafter1'
  

  export default {
    name: 'OneElectricalList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      JSelectDepart,
      OneElectricalModal,
      JSearchSelectTag,
      Elemain,
      Eledanger,
      Elebefore,
      Eleafter,
      Elemain1,
      Eledanger1,
      Elebefore1,
      Eleafter1
    },
    data () {
      return {
        width:'900px',
         confirmLoading: false,
         value:'',
        visible:false,
       elemain:true,
       eledanger:false,
       elebefore:false,
       eleafter:false,
         confirmLoading1: false,
        visible1:false,
       elemain1:true,
       eledanger1:false,
       elebefore1:false,
       eleafter1:false,
         expandedKeys: ['0-0'],
      autoExpandParent: true,
      checkedKeys: ['0-0-0'],
      selectedKeys: [],
      treeData,
      queryParam: { ticketType: 'd1' },
        description: '电气第一种工作票管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'工作内容',
            align:"center",
            dataIndex: 'workDetail'
          },
          {
            title:'任务单编号',
            align:"center",
            dataIndex: 'rwdId'
          },
          {
            title:'开票时间',
            align:"center",
            dataIndex: 'createTime',
          },
           {
            title:'风电场名称',
            align:"center",
            dataIndex: 'orgName_dictText'
          },
           {
            title:'操作人',
            align:"center",
            dataIndex: 'operatePerson'
          },
          {
            title:'监护人',
            align:"center",
            dataIndex: 'protectPerson'
          },
          {
            title:'值班负责人',
            align:"center",
            dataIndex: 'ondutyPerson'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/eleswitch/eleSwitch/list?protectPerson=1",
          delete: "/one_electrical/oneElectrical/delete",
          deleteBatch: "/one_electrical/oneElectrical/deleteBatch",
          exportXlsUrl: "/one_electrical/oneElectrical/exportXls",
          importExcelUrl: "one_electrical/oneElectrical/importExcel",
          edit:'/eleswitch/eleSwitch/edit'
        },
        dictOptions:{},
      }
    },
    created() {
    },
    watch: {
    checkedKeys(val) {
      console.log('onCheck', val);
    },
  },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      handleChange(value) {
      if(value.key == 'main'){
        this.elemain = true
        this.eledanger = false
        this.elebefore = false
         this.eleafter = false
         this.width = '900px'
      }else if(value.key == 'danger'){
        this.eledanger = true
        this.elemain = false
        this.elebefore = false
         this.eleafter = false
         this.width = '750px'
      }else if(value.key == 'before'){
        this.elebefore = true
        this.elemain = false
        this.eledanger = false
         this.eleafter = false
          this.width = '750px'
      }else if(value.key == 'after'){
        this.eleafter = true
         this.elebefore = false
        this.elemain = false
        this.eledanger = false
         this.width = '800px'
      }
    },
     handleChange1(value) {
      if(value.key == 'main'){
        this.elemain1 = true
        this.eledanger1 = false
        this.elebefore1 = false
         this.eleafter1 = false
         this.width = '900px'
      }else if(value.key == 'danger'){
        this.eledanger1 = true
        this.elemain1 = false
        this.elebefore1 = false
         this.eleafter1 = false
         this.width = '750px'
      }else if(value.key == 'before'){
        this.elebefore1 = true
        this.elemain1 = false
        this.eledanger1 = false
         this.eleafter1 = false
          this.width = '750px'
      }else if(value.key == 'after'){
        this.eleafter1 = true
         this.elebefore1 = false
        this.elemain1 = false
        this.eledanger1 = false
         this.width = '800px'
      }
    },
      Detail(value){
          console.log('洗钱切割',value)
        this.value = value
      this.visible = true;
      },

      Detail1(value){
          console.log('222',value)
          this.value = value
      this.visible1 = true;
      },
      yes(){
        console.log('queding11',this.$refs.ch.refresh())

        if(this.$refs.ch.refresh() == 's_t'){  //主票
          this.url.edit = '/eleswitch/eleSwitch/edit'
        }else if(this.$refs.ch.refresh() == 's_d') {//危险点
          this.url.edit = '/eleswitchdanger/eleSwitchDanger/edit'
        }else if(this.$refs.ch.refresh() == 's_b'){ //前
          this.url.edit = '/eleswitcheck_b/eleSwitchCheckb/edit '
        }else if(this.$refs.ch.refresh() == 's_a'){ //后
          this.url.edit = '/eleswitcheck_a/eleSwitchChecka/edit '
        }
        var params = this.$refs.ch.back()
       
       putAction(this.url.edit,params).then(res=>{
         console.log('jieguo',res)
          if(res.code == 200){
          this.confirmLoading = true;
          this.visible = false;
          this.confirmLoading = false;
          if(res.result == '无法更新操作票,请先填写危险点控制措施票与操作前准备票!'){
            this.$message.warning(res.result);
          }
          this.searchQuery()
         }
       })

      },
       handleOk(e) {
      this.confirmLoading = true;
        this.visible = false;
        this.confirmLoading = false;
    
      },
    print(){
      console.log('123打印')
      },
    handleCancel(e) {
      console.log('Clicked cancel button');
      this.visible = false;
      },

      handleOk1(e) {
      this.confirmLoading1 = true;
        this.visible1 = false;
        this.confirmLoading1 = false;
      },
    
    handleCancel1(e) {
      this.visible1 = false;
      },



     
      onExpand(expandedKeys) {
      console.log('onExpand', expandedKeys);
      this.expandedKeys = expandedKeys;
      this.autoExpandParent = false;
    },
    onCheck(checkedKeys) {
      console.log('onCheck', checkedKeys);
      this.checkedKeys = checkedKeys;
    },
    onSelect(selectedKeys, info) {
      console.log('onSelect', selectedKeys);
      this.selectedKeys = selectedKeys;
       this.$router.push({
          name:selectedKeys,
          
        })
    },
    },
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>